package com.mx.tool.form.window.other;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import org.apache.commons.lang3.StringUtils;

import javax.swing.*;
import java.util.Locale;

/**
 * @Author: 徐建鹏.
 * @create: 2021-11-19 14:39
 * @Description:
 */
public class CreateWindow {

    private JPanel jPanel;
    private JButton numberButton;
    private JTextField numLengthText;
    private JTextField numResultText;
    private JButton loButton;
    private JTextField loLengthText;
    private JTextField loResultText;
    private JButton upButton;
    private JTextField upLengthText;
    private JTextField upResultText;
    private JButton zmButton;
    private JTextField zmLengthText;
    private JTextField zmResultText;
    private JButton uuidButton;
    private JTextField uuidResultText;

    public CreateWindow() {
        uuidButton.addActionListener(e -> uuidResultText.setText(IdUtil.fastSimpleUUID()));
        numberButton.addActionListener(e -> {
            String numLengthTextStr = numLengthText.getText();
            if (StringUtils.isNotBlank(numLengthTextStr)) {
                int length = Convert.toInt(numLengthTextStr);
                if (length > 0) {
                    numResultText.setText(RandomUtil.randomNumbers(length));
                }
            }
        });
        loButton.addActionListener(e -> {
            String loLengthTextStr = loLengthText.getText();
            if (StringUtils.isNotBlank(loLengthTextStr)) {
                int length = Convert.toInt(loLengthTextStr);
                if (length > 0) {
                    loResultText.setText(RandomUtil.randomString(RandomUtil.BASE_CHAR, length));
                }
            }
        });
        upButton.addActionListener(e -> {
            String upLengthTextStr = upLengthText.getText();
            if (StringUtils.isNotBlank(upLengthTextStr)) {
                int length = Convert.toInt(upLengthTextStr);
                if (length > 0) {
                    upResultText.setText(RandomUtil.randomString(RandomUtil.BASE_CHAR, length).toUpperCase(Locale.ROOT));
                }
            }
        });
        zmButton.addActionListener(e -> {
            String zmLengthTextStr = zmLengthText.getText();
            if (StringUtils.isNotBlank(zmLengthTextStr)) {
                int length = Convert.toInt(zmLengthTextStr);
                if (length > 0) {
                    zmResultText.setText(RandomUtil.randomString(RandomUtil.BASE_CHAR + RandomUtil.BASE_CHAR.toUpperCase(Locale.ROOT), length));
                }
            }
        });
    }

    public JPanel getContent() {
        return jPanel;
    }
}
